<!-- 功能：FCSAN管理 | 作者：menghao.yan | 邮箱：yxs2615@163.com | 时间：2023年08月22日 22:58:00 -->
<template>
  <a-tabs v-model:activeKey="activeKey" type="card" class="y-tabs">
    <a-tab-pane key="fcShuChu" tab="FC输出">
      <a-card>
        <a-row align="middle">
          <a-col :span="16">
            <a-space>
              <a-button type="link" class="y-btn" @click="openTianJiaSheBeiModal">
                <template #icon>
                  <plus-outlined />
                </template>
                添加设备
              </a-button>
              <!-- 弹窗 - 添加设备 -->
              <tianJiaSheBeiModal v-model:visible="visibleTianJiaSheBeiModal"></tianJiaSheBeiModal>
              <a-button type="link" class="y-btn" @click="keHuDuanChongLian">
                <template #icon>
                  <sync-outlined />
                </template>
                客户端重连
              </a-button>
              <a-button type="link" class="y-btn y-close-fcsan-fuwu" @click="tingZhiFcsanFuWu">
                <template #icon>
                  <poweroff-outlined />
                </template>
                停止FCSAN服务
              </a-button>
            </a-space>
          </a-col>
          <a-col :span="8">
            <a-input v-model:value="searchValueFcShuChu">
              <template #addonBefore>
                <search-outlined /> 搜索:
              </template>
            </a-input>
          </a-col>
        </a-row>
        <a-table bordered :data-source="dataSourceFcShuChu" :columns="columnsFcShuChu" class="y-table" :pagination="paginationFcShuChu">
        </a-table>
      </a-card>
    </a-tab-pane>

    <a-tab-pane key="fcFangWenKongZhi" tab="FC访问控制">
      <a-row>
        <a-col :span="24">
          <a-alert banner message="提示: 同一个target,一个initiator节点仅能被一个组绑定,默认组包含不属于该 Target其他组的所有initiator节点!" type="warning" show-icon />
        </a-col>
      </a-row>
      <a-card>
        <a-table bordered :data-source="dataSourceFcFangWenKongZhi" :columns="columnsFcFangWenKongZhi" class="y-table" :pagination="paginationFcFangWenKongZhi">
          <template #bodyCell="{ text, column, record }">
            <template v-if="column.key === 'name'">
              <a-space class="y-fc-fangwenkongzhi-table-name">
                <span>{{text}}</span>
                <a-tooltip color="#2e6e9e" placement="right">
                  <template #title>添加组</template>
                  <a-button type="link" @click="openTianJiaZuModal">
                    <template #icon>
                      <plus-outlined />
                    </template>
                  </a-button>
                  <!-- 弹窗 - 添加设备 -->
                  <tianJiaZuModal v-model:visible="visibleTianJiaZuModal"></tianJiaZuModal>
                </a-tooltip>
              </a-space>
            </template>
          </template>
        </a-table>
      </a-card>
    </a-tab-pane>
  </a-tabs>
</template>

<script setup>
import tianJiaSheBeiModal from './modal/tianJiaSheBeiModal.vue'
import tianJiaZuModal from './modal/tianJiaZuModal.vue'
import { ExclamationCircleOutlined } from '@ant-design/icons-vue'
import { Modal } from 'ant-design-vue'
const activeKey = ref('fcShuChu')

// -- Target
const visibleTianJiaSheBeiModal = ref(false)

const openTianJiaSheBeiModal = () => {
  visibleTianJiaSheBeiModal.value = true
}

const tingZhiFcsanFuWu = () => {
  Modal.confirm({
    title: '确认操作',
    icon: h(ExclamationCircleOutlined),
    content: '您确定要停止FCSAN服务?',
    okText: '确定',
    okType: 'danger',
    cancelText: '取消',
    onOk() {
      console.log('OK')
    },
    onCancel() {
      console.log('Cancel')
    }
  })
}
const searchValueFcShuChu = ref('')

// 表格列
const columnsFcShuChu = ref([
  {
    title: '设备名称',
    dataIndex: 'name',
    key: 'name',
    align: 'center',
    sorter: {
      compare: (a, b) => a.name.localeCompare(b.name),
      multiple: 1
    }
  },
  {
    title: 'Target名称',
    dataIndex: 'targetName',
    key: 'targetName',
    align: 'center',
    sorter: {
      compare: (a, b) => a.targetName.localeCompare(b.targetName),
      multiple: 2
    }
  },
  {
    title: '组名',
    dataIndex: 'zuMing',
    key: 'zuMing',
    align: 'center',
    sorter: {
      compare: (a, b) => a.zuMing.localeCompare(b.zuMing),
      multiple: 3
    }
  }
])

// 表格数据
const visibleTianJiaZuModal = ref(false)

const openTianJiaZuModal = () => {
  visibleTianJiaZuModal.value = true
}

const dataSourceFcShuChu = ref([
  {
    key: '1',
    name: 'FC-1',
    targetName: 'Target-1',
    zuMing: '组-1'
  }
])

// 分页
const paginationFcShuChu = {
  current: 1,
  pageSize: 10,
  showQuickJumper: true,
  showSizeChanger: true,
  total: 0,
  showTotal: (total, range) => {
    return `${range[0]}-${range[1]} 共 ${total} 条数据`
  },
  onChange: (page, pageSize) => {
    console.log('FCSAN管理 > FC输出分页改变>>', page, pageSize)
  }
}

// -- CHAP认证用户

// 表格列
const columnsFcFangWenKongZhi = ref([
  {
    title: 'Target名称',
    dataIndex: 'name',
    key: 'name',
    align: 'center',
    sorter: {
      compare: (a, b) => a.name.localeCompare(b.name),
      multiple: 1
    }
  },
  {
    title: '组名',
    dataIndex: 'zuMing',
    key: 'zuMing',
    align: 'center',
    sorter: {
      compare: (a, b) => a.zuMing.localeCompare(b.zuMing),
      multiple: 2
    }
  },
  {
    title: '客户端Initiator节点',
    dataIndex: 'initiator',
    key: 'initiator',
    align: 'center',
    sorter: {
      compare: (a, b) => a.initiator.localeCompare(b.initiator),
      multiple: 3
    }
  }
])

// 表格数据
const dataSourceFcFangWenKongZhi = ref([
  {
    key: '1',
    name: 'FC-1',
    zuMing: '组-1',
    initiator: 'Initiator-1'
  }
])

// 分页
const paginationFcFangWenKongZhi = {
  current: 1,
  pageSize: 10,
  showQuickJumper: true,
  showSizeChanger: true,
  total: 0,
  showTotal: (total, range) => {
    return `${range[0]}-${range[1]} 共 ${total} 条数据`
  },
  onChange: (page, pageSize) => {
    console.log('FCSAN管理 > FC访问控制分页改变>>', page, pageSize)
  }
}
</script>

<style scoped lang='scss'>
.ant-row {
  margin-bottom: 10px;
}

.y-close-fcsan-fuwu {
  color: red;
}
.y-fc-fangwenkongzhi-table-name {
  color: #67c23a;
}
</style>